package com.da.javatest.niuke.jianzhi;

import java.util.Arrays;

/**
 * @author chenlida
 * @date 2020/10/20 19:49
 * https://www.nowcoder.com/practice/beb5aa231adc45b2a5dcc5b62c93f593?
 * tpId=13&tags=&title=&diffculty=0&judgeStatus=0&rp=1
 */
public class C13Solution {
    public static void reOrderArray(int[] array) {
        int length = array.length;
        int[] datas = new int[length];
        int index = 0;
        int lastIndex = length - 1;
        for (int i : array) {
            if ((i & 1) == 1) {
                datas[index] = i;
                index++;
            } else {
                if (length - 1 - lastIndex >= 0) {
                    System.arraycopy(datas, lastIndex + 1, datas, lastIndex, length - 1 - lastIndex);
                }
                datas[length - 1] = i;
                lastIndex--;
            }
        }
        for (int i = 0; i < length; i++) {
            array[i] = datas[i];
        }
        array = datas;
        System.out.println(Arrays.toString(array));
    }

    public static void main(String[] args) {
        reOrderArray(new int[] {1, 2, 3, 4, 5, 6, 7});
    }
}
